text = input()
fullnumbertext = ''
fullnumber = ''
text_test = 0
text_testprobels = 0
text_numbers = []
parametr = 0
parametr2 = 0
listwithnumbertext = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
listwithnumber = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
while text_test != len(text):
    if text[text_test] == " ":
        text_numbers.append(text[parametr:text_test])
        parametr = text_test + 1
        text_testprobels += 1
    if text_test == len(text) - 1:
        text_numbers.append(text[parametr:])
    text_test += 1
while parametr2 != len(text_numbers):
    if text_numbers[parametr2] in listwithnumbertext:
        fullnumbertext += listwithnumber[listwithnumbertext.index(text_numbers[parametr2])]
        parametr2 += 1
    else:
        break
fullnumber = int(fullnumbertext)
fullnumbertext = str(fullnumber)
x_for_plus = fullnumber
x_for_minus = fullnumber
raznica_for_x_plus = 0
raznica_for_x_minus = 0
raznica2_for_x_plus = 1
raznica2_for_x_minus = 1
raznica_finish_for_x_plus = 0
raznica_finish_for_x_minus = 0
delitel_for_x_plus = 2
delitel_for_x_minus = 2
while raznica2_for_x_plus != 0:
    while delitel_for_x_plus != x_for_plus - 1:
        if x_for_plus % delitel_for_x_plus == 0:
            raznica_for_x_plus += 1
        delitel_for_x_plus += 1
        if raznica_for_x_plus > 0:
            x_for_plus += 1
            delitel_for_x_plus = 2
            raznica_for_x_plus = 0
            raznica2_for_x_plus += 1
            raznica_finish_for_x_plus = raznica2_for_x_plus - 1
        if (delitel_for_x_plus == x_for_plus - 2) and (raznica_for_x_plus == 0):
            raznica2_for_x_plus = 0
while raznica2_for_x_minus != 0:
    while delitel_for_x_minus != x_for_minus - 1:
        if x_for_minus % delitel_for_x_minus == 0:
            raznica_for_x_minus += 1
        delitel_for_x_minus += 1
        if raznica_for_x_minus > 0:
            x_for_minus -= 1
            delitel_for_x_minus = 2
            raznica_for_x_minus = 0
            raznica2_for_x_minus += 1
            raznica_finish_for_x_minus = raznica2_for_x_minus - 1
        if (delitel_for_x_minus == x_for_minus - 2) and (raznica_for_x_minus == 0):
            raznica2_for_x_minus = 0
if (raznica_finish_for_x_minus > raznica_finish_for_x_plus) and (len(fullnumbertext) == 3):
    print(x_for_plus)
if (raznica_finish_for_x_plus > raznica_finish_for_x_minus) and (len(fullnumbertext) == 3):
    print(x_for_minus)
if (raznica_finish_for_x_minus == raznica_finish_for_x_plus) and (len(fullnumbertext) == 3):
    print(x_for_minus)
if (len(fullnumbertext) < 3) or (len(fullnumbertext) > 3):
    print("Wrong input")
